package com.blacktea.behavioralpatterns.commandpattern;

import java.util.Stack;

/**
 * @description: 命令执行器类
 * @author: black tea
 * @date: 2023/3/24 20:23
 */
public class CommandExecutor {

    private final Stack<Command> historyStack;

    public CommandExecutor() {
        this.historyStack = new Stack<>();
    }

    public void executeCommand(Command command){
        command.execute();
        historyStack.push(command);
    }

    public void undoCommand(){
        if (!historyStack.isEmpty()){
            // 进行撤回操作
            Command command = historyStack.pop();
            command.undo();
        }
    }

}
